<?php
namespace app\supermanager\controller;
use think\Controller;
use app\common\traits\controller\TraitController;
use think\Loader;
use think\Db;
/**
 * 会员管理
 */
class User extends Controller
{
	use TraitController;
	/**
	 * 初始化操作
	 */
	protected function init()
    {
        if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
    }
	//会员信息列表
	public function index()
	{
		$list = Loader::model('Users')->getUserList(input('get.'));
		$branchs = Loader::model('Filiales')->column('name','id');
		return view('user/index',['list' => $list, 'branchs' => $branchs]);
	}
	/**
	 * 会员详情
	 */
	public function read($id)
	{
		$userInfo = Loader::model('Users')->getUserInfo($id);
		$contactioninfo = Db::table('contactioninfo')->where('user_id',$id)->select();
		return view('user/read',['userInfo' => $userInfo, 'contactioninfo' => $contactioninfo]);
	}

	//////////////////////////////////实名认证模块//////////////////////////////////////
    /**
     * [FunctionName 列表]
     * @param string $value [description]
     */
    public function RZList()
    {
    	$Rzlist = db('user_certification')->select();
		return view('user/rzindex',['Rzlist'=>$Rzlist]);
    }
    /**
     * [FunctionName 查看]
     * @param string $value [description]
     */
    public function RZInfo($id)
    {
    	$info = db('user_certification')->where('id',$id)->find();
    	$rz = db('users')->where('id',$info['user_id'])->value('authentication');
		return view('user/waitrenzh',['info'=>$info,'rz'=>$rz]);
    }
    /**
     * [FunctionName 认证]
     * @param string $value [description]
     */
    public function RZPass()
    {
    	$name = input('post.name');
    	$ID_number = input('post.number');
    	$user_id = db('user_certification')->where('card_id',$ID_number)->value('user_id');
    	$res = model('Authentication')->Check($user_id,$name,$ID_number);
    	if ($res['isok']==1&&$res['code']==1) {
    		$re = db('users')->where('id',$user_id)->setField('authentication',1);
    		if ($re) {
    			return $this->success($res['messsage'],'/users');
    		}
    	}else{
    		return $this->error($res['messsage']);
    	}
    }
}